<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/4/13
 * Time: 10:01
 */

namespace App\Rep;


use App\Models\MaterialSpecification;

class MaterialSpecificationRep
{

    /**
     * 获取材料规格列表
     * @param $params
     */
    public function getMaterialSpecificationListRep($params){
        return MaterialSpecification::Search($params)
            ->orderBy('id','desc')
            ->paginate($params['per_page']??10);
    }

    /**
     * 添加材料规格
     * @param $params
     */
    public function createMaterialSpecificationRep($params){
        if(isset($params['id']) && !empty($params['id'])){
            $model = MaterialSpecification::where('id',$params['id'])->first();
        }else{
            $model = MaterialSpecification::where('name',$params['name'])->first();
            if($model){
                return ['code'=>1015,'data'=>[],'msg'=>'该名称已存在'];
            }
            $model = new MaterialSpecification();
        }
        $model->name = $params['name'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }

    /**
     * 删除材料规格
     * @param $params
     */
    public function delMaterialSpecificationRep($params){
        $model = MaterialSpecification::where('id',$params['id'])->first();
        $model->is_del = $params['is_del'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }
}